<table class="table">
  <thead>
  <tr>
    <th>Action</th>
    <th>By</th>
    <th>Changed</th>
  </tr>
  </thead>
  <tbody>
  <% audits.each do |audit| %>
    <tr>
      <td><%= link_to audit.action, audit_path(audit) %></td>
      <td>
        <% if global %>
          <%= (begin; audit.auditable;rescue NameError;end) ? link_to_resource(audit.auditable) : "#{audit.auditable_type} #{audit.auditable_id}" %>
          by
          <br/>
        <% end %>

        <%= audit_author audit %>
        <br/>

        <%= render_time audit.created_at %>
        <%= additional_info "From #{audit.remote_address} request #{audit.request_uuid}" %>
      </td>
      <td>
        <% audit.audited_changes.to_a.each do |column, (before, after)| %>
          <%= column %>:
          <% if audit.action == "update" # others are just attribute hashes %>
            <% if before.is_a?(String) && after.is_a?(String) && (before + after).count("\n").nonzero? %>
              <%= Samson::Diff.text_diff before, after %>
              <details>
                Before:<br/>
                <%= simple_format readable_ruby_value before %>
                <br/>
                After:<br/>
                <%= simple_format readable_ruby_value after %>
              </details>
            <% else %>
              <%= readable_ruby_value before %> → <%= readable_ruby_value after %>
            <% end %>
          <% else %>
            <%= readable_ruby_value before %>
          <% end %>
          <br/>
        <% end %>
      </td>
    </tr>
  <% end %>
  </tbody>
</table>

<%= paginate @pagy if @pagy %>

<%= Samson::Diff.style_tag %>
